<template>
  <Layout title="项目管理" showHome showNew>
    <van-search
      v-model="query.name"
      placeholder="请输入项目名称查询"
      show-action
      background="#ffd591"
      shape="round"
    >
      <template #action>
        <div @click="onSearch">搜索</div>
      </template>
    </van-search>
    <van-pull-refresh v-model="loading" @refresh="onRefresh">
      <van-swipe-cell v-for="it in projectList" key="it.id">
        <van-cell-group style="margin-bottom: 10px">
          <van-cell title="项目名称：">{{ it.name }}</van-cell>
          <van-cell title="项目负责人：">{{ it.liableName }}</van-cell>
          <van-cell title="项目签订时间：">{{
            it.signTime.substring(0, 10)
          }}</van-cell>
        </van-cell-group>
        <template #right>
          <van-button
            style="height: 100%"
            square
            type="danger"
            text="删除"
            @click="deleteEvt(it.id)"
          />
          <van-button style="height: 100%" square type="primary" text="编辑" />
        </template>
      </van-swipe-cell>
    </van-pull-refresh>
  </Layout>
</template>
<script setup>
import {
  showConfirmDialog,
  showSuccessToast,
  showFailToast,
  BackTop,
} from "vant";
import { ref, onMounted, reactive, getCurrentInstance } from "vue";
import { projectListApi, projectDeleteApi } from "../../apis/projectApi";

const loading = ref(false);
const query = reactive({
  name: "",
  page: 1,
  size: 50,
});
let projectList = ref([]);
onMounted(function () {
  getList();
});
async function getList() {
  let result = await projectListApi(query);
  if (result.code === 200) {
    projectList.value = result.data.rows;
    // console.log(projectList.value);
  }
}
/**搜索框 */
function onSearch() {
  getList();
}
/**下拉刷新 */
function onRefresh() {
  setTimeout(() => {
    loading.value = false;
  }, 1000);
}
/**删除功能 */
function deleteEvt(id) {
  // 确认删除框
 
  showConfirmDialog({
    title:'删除',
    message: "确认删除吗？此操作不可更改",
  })
    .then(async () => {
      let result =await projectDeleteApi(id);
      if (result.code === 200) {
        showSuccessToast("删除成功");
        getList();
      }
    })
    .catch(() => {
      // on cancel
    });
}
// let result =await projectDeleteApi(id);
//       if (result.code === 200) {
//         showSuccessToast("删除成功");
//         getList();
//       }
// }

</script>
<style lang="less">
@import url("../../style/common.less");
</style>
